package com.lzy.crm.wechat.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lzy.crm.base.util.StringUtil;
import com.lzy.crm.domain.GameScoreLocker;
import com.lzy.crm.domain.PlayerInRoomInfo;
import com.lzy.crm.service.PlayerInRoomInfoService;

/**
 *  房间邀请控制器
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/wechat")
public class RoomInviteController {
	
	
	Logger logger= Logger.getLogger(RoomInviteController.class);
	
	@Resource
	private PlayerInRoomInfoService playerInRoomInfoService;
	
	/**
	 * 房间邀请链接
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/room_invite")
	public String roomInvite(HttpServletRequest request, ModelMap model) {
		String roomId = request.getParameter("roomId");
		try {
			List<PlayerInRoomInfo> playerInRoomInfoList = playerInRoomInfoService.getPlayerInRoomInfoByroomId(roomId);
			if(playerInRoomInfoList!=null&&playerInRoomInfoList.size()>0){
				PlayerInRoomInfo playerInRoomInfo = playerInRoomInfoList.get(0);
				GameScoreLocker gameScoreLocker = playerInRoomInfoService.getGameScoreLockerByUserId(playerInRoomInfo.getCreateRoomUserID().toString());
				model.put("gameScoreLocker", gameScoreLocker);
				model.put("playerInRoomInfo", playerInRoomInfo);
				model.put("playerInRoomInfoList", playerInRoomInfoList);
				model.put("playerCount", playerInRoomInfo.getRoomMaxPlayer()-playerInRoomInfoList.size());
				String gameName ="";
				if(26== gameScoreLocker.getKindID()){
					gameName = "桂阳字牌";
				}if(27== gameScoreLocker.getKindID()){
					gameName = "郴州字牌";
				}if(30== gameScoreLocker.getKindID()){
					gameName = "跑得快";
				}if(1006== gameScoreLocker.getKindID()){
					gameName = "有乐牛牛";
				}if(315== gameScoreLocker.getKindID()){
					gameName = "红中麻将";
				}
				model.put("gameName", gameName);
			}else{
				model.put("playerCount", 0);
				model.put("","该连接已过期");
			}
			
		} catch (Exception e) {
			logger.error(e);
		}
		
		return "wechat/room/room_invite"; 
	}
	
	
	
	
	
	

}
